package com.wondertek.poms.sync.manager.mixed;

import java.util.Date;

import org.apache.commons.lang3.time.FastDateFormat;

import com.wondertek.poms.dao.po.PrdCont;
import com.wondertek.poms.dao.po.PrdInfo;

import cn.hutool.core.util.StrUtil;

/**
 * 混编发送对象
 * @author douzi
 */
public class MixedSendData {
	public String type; //“301”--分包批价消息 “302”--发布消息 “401”--播控消息
	public DataBody data;
	
	public MixedSendData(String type, DataBody data) {
		this.type = type;
		this.data = data;
	}
	
	public MixedSendData(PrdCont pc, PrdInfo pi, String type) {
		DataBody db = new DataBody();
		db.programId = pc.getPrdContId();
		db.contentId = Long.parseLong(pc.getContentId());
		db.assetId = pc.getMmsId();
		//db.userId = ""; //没有
		db.userName = pc.getOperator();
		db.status = "1"; //0-失败 1-成功 2-开始
		db.timestamp = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss.SSS").format(new Date());

		if ("1301".equals(type)) {
			DetailCharge dc = new DetailCharge();
			if (pi != null) {
				dc.packageId = pi.getProductInfoPackageId();
				dc.packageName = pi.getName();
				dc.productId = pi.getFirstProductInfoPackageId();
				//dc.product = ""; //没有
				db.detail = dc;
			}
		} else if ("1401".equals(type)) {
			db.userName = pc.getBcPerson();
			db.remarks = pc.getBcPerson();
			DetailBc dbc = new DetailBc();
			dbc.brocPartyId = pc.getBcId() + "";
			//dbc.brocPartyName = ""; //没有
			if (pc.getBcStatus() == 2) {
				db.status = "0";
			}
			db.detail = dbc;
		} else if ("1302".equals(type)) {
			db.userName = "";// 发布暂时还没发布人
			if (pc.getPublishNoVOMSStatus() == 22) {
				db.status = "0";
			}
			DetailCharge dc = new DetailCharge();
			if (pi != null) {
				dc.packageId = pi.getProductInfoPackageId();
				dc.packageName = pi.getName();
				dc.productId = pi.getFirstProductInfoPackageId();
				//dc.product = ""; //没有
				db.detail = dc;
			}
		}

		//同步操作人都为空，定时发布操作人为空，混编需要默认值，为空时设置为administrator
		if (StrUtil.isBlank(db.userName)) {
			db.userName = "administrator";
		}

		this.type = type;
		this.data = db;
	}

	public MixedSendData() {
	}

	public class DataBody {
		public Long programId;
		public Long contentId;
		public Long assetId;
		public Long userId;
		public String userName;
		public String status;
		public String timestamp;
		public String remarks;
		public Object detail;
		
		public DataBody(Long programId, Long contentId, Long assetId,
				Long userId, String userName, String status,
				String timestamp, String remarks, Object detail) {
			super();
			this.programId = programId;
			this.contentId = contentId;
			this.assetId = assetId;
			this.userId = userId;
			this.userName = userName;
			this.status = status;
			this.timestamp = timestamp;
			this.remarks = remarks;
			this.detail = detail;
		}
		
		public DataBody() {
			super();
		}
	}
	
	public class DetailCharge {
		public Long productId;
		public String product;
		public Long packageId;
		public String packageName;
		
		public DetailCharge(Long productId, String product, Long packageId,
				String packageName) {
			super();
			this.productId = productId;
			this.product = product;
			this.packageId = packageId;
			this.packageName = packageName;
		}
		
		public DetailCharge() {
			super();
		}
	}

	public class DetailBc {
		public String brocPartyId;
		public String brocPartyName;
		
		public DetailBc(String brocPartyId, String brocPartyName) {
			super();
			this.brocPartyId = brocPartyId;
			this.brocPartyName = brocPartyName;
		}

		public DetailBc() {
			super();
		}
	}
}
